<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Gallery/classes/PhpFox_ComponentMyGallery.class.php, $Author:  $ */



/** Component for viewing member pictures
 *
 * @version $Id: PhpFox_ComponentMyGallery.class.php 365 2008-02-25 18:02:46Z phpfoxsv $
 * @package module.gallery
 */
class PhpFox_Mod_Gallery_ComponentMyGallery extends BaseComponent
{
    function process()
    {
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        $oReq = &App::getRequest();
        $oTpl = $this->_oModule->getTemplate();

        $iUserId = $this->getParam('userId');

		if ( !$iUserId )
		{
			return '';
		}
        if (!App::getSetting('profile_show_gallery'))
        {
            $oTpl->assign(array(
                'bHide' => true,
            ));
            return $oTpl->fetch('MyGallery.html');
        }
        if (!$oSecurityService->checkAccess('gallery', '', false))
        {
            $oTpl->assign(array(
                'bHide' => true,
            ));
            return $oTpl->fetch('MyGallery.html');
        }
        if (!$oSecurityService->checkPerm('gallery', array('read_only', 'full'), false))
        {
            $oTpl->assign(array(
                'bHide' => true,
            ));
            return $oTpl->fetch('MyGallery.html');
        }
        $sUser = $oReq->get('name');
        
        $sWhoView = '';
        if (!App::isStaff())
        {
        	if ( $iUserId != App::getUser('id') )
        	{
        		$oSrvFriend = &App::getModuleService('Account', 'Friends');
        		$sWhoView = ($oSrvFriend->checkIsFriend($sUser, App::getUser('user')) ? 'AND who_view != "2"' : 'AND who_view = ""');
        	}
        }
        
        $oSrvGallery = $this->_oModule->getService('Gallery');

        if (!$oSrvGallery->myGalleryCount($iUserId, $sWhoView))
        {
        	return '';
        }
        
        $aItems = $this->oDatabase->getRows('SELECT id FROM `'. App::getT('main') .'`'.
        	' WHERE user_id = "'. $iUserId .'" ' . $sWhoView . ' AND allow = "" '.
        	' ORDER BY time DESC LIMIT 0,'. App::getParam('public.mypage.gallery') .'');

        $oTpl->assign(array(
            'aItems'    => $aItems,
            'sUser' => $sUser,
            'sImageUrl' => App::getParam('gallery.pic.url'),
        ));
        return $oTpl->fetch('MyGallery.html');
    }
}
?>